import { SERVER_PORT } from "./constants/index";
import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { BookModule } from './book/book.module';
import * as Joi from '@hapi/joi';
import { MongooseModule } from '@nestjs/mongoose';
import CONFIG from "./config";
import { UploadModule } from "./uploader/upload.module";

// 业务模块
const businessModules = [
  BookModule,
  UploadModule
]

// 工具模块
const libModules = [
  ConfigModule.forRoot({
    isGlobal: true,
    validationSchema: Joi.object({
      ENV: Joi.string().valid('development', 'production', 'local').default('local'),
      PORT: Joi.number().default(SERVER_PORT)
    })
  }),
  MongooseModule.forRoot(CONFIG.mongoose.uri, CONFIG.mongoose.options)
]

@Module({
  imports: [...libModules, ...businessModules]
})
export class AppModule {}